from selenium.webdriver.common.by import By
from webAutomation.base.base_page import BasePage, BaseHandle


# 对象层
# 登录页面类
class LoginPage(BasePage):
    def __init__(self):
        # 继承父类
        super().__init__()
        # 输入用户名
        self.username = By.CSS_SELECTOR, "[placeholder='请输入用户名']"
        # 输入密码
        self.password = By.CSS_SELECTOR, "[placeholder='请输入密码']"
        # 登录按钮
        self.login_btn = By.XPATH, "//*[@id='login']/div/form/div[3]/div/button[1]/span"

    # 查找用户名输入框
    def find_username(self):
        return self.find_element(self.username)

    # 查找密码输入框
    def find_password(self):
        return self.find_element(self.password)

    # 查找登录按钮
    def find_login_btn(self):
        return self.find_element(self.login_btn)

# 操作层
class LoginHandle(BaseHandle):
    def __init__(self):
        # 实例化登陆页面类
        self.login_page = LoginPage()

    # 输入用户名
    def input_username(self, username):
        self.input_text(self.login_page.find_username(), username)

    # 输入密码
    def input_password(self, password):
        self.input_text(self.login_page.find_password(), password)

    # 点击登录按钮
    def click_login_btn(self):
        self.login_page.find_login_btn().click()

# 业务层
class LoginProxy:
    def __init__(self):
        self.login_handle = LoginHandle()

    # 实现登录操作
    def login(self,username, password):
        print("----------login start...-----------")
        # 输入手机号
        self.login_handle.input_username(username)
        # 输入密码
        self.login_handle.input_password(password)
        # 点击登录按钮
        self.login_handle.click_login_btn()
        print("----------login end...-----------")